﻿using Axiom.Hermetica.WPF.ViewModels;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;

namespace Axiom.Hermetica.WPF
{
	public partial class App : Application
	{
		private static ViewModel _model;

		public static ViewModel Model
		{
			get
			{
				if (App._model == null)
				{
					App._model = ViewModelLocator.GetMainViewModel();
				}
				return App._model;
			}
			set
			{
				App._model = value;
			}
		}

		private void Application_Exit_1(object sender, ExitEventArgs e)
		{
			Model.Save();

			DateTime start = DateTime.Now;
			TimeSpan period = TimeSpan.FromMilliseconds(0);
			do
			{
				Thread.Sleep(100);
				period = DateTime.Now - start;
			} while (Model.IsBusy && period < TimeSpan.FromSeconds(30));
		}
	}
}
